#include "Renderer_PCH.h"
#include "RenderQuadEvent.h"

/*--------------------------------------------------------------------------*/

RenderQuadEvent::RenderQuadEvent(const std::string& name)
{
	if (name == "POSTPROCESS")
	{
		m_event = ERenderQuadEvents::POSTPROCESS;
	}
	else if (name == "PREPOSTPROCESS")
	{
		m_event = ERenderQuadEvents::PREPOSTPROCESS;
	}
	else
	{
		m_event = ERenderQuadEvents::UNKNOWN;
	}
}

/*--------------------------------------------------------------------------*/

RenderQuadEvent::~RenderQuadEvent()
{

}

/*--------------------------------------------------------------------------*/

bool RenderQuadEvent::CallEvent()
{
	switch (m_event)
	{
	case ERenderQuadEvents::POSTPROCESS:
		{
			g_Renderer->GetPostprocessMgr()->SetMaterial();
			break;
		}
	case ERenderQuadEvents::PREPOSTPROCESS:
		{
			g_Renderer->GetPostprocessMgr()->SetDSMaterial();
			break;
		}
	case ERenderQuadEvents::UNKNOWN:
	default:
		{
			__Error("UNKNOWN type in RenderQuatEvent!");
		}
	}

	DynamicSurface* ds = g_Renderer->GetDynGeometryMgr()->BeginGeometry(6, EVertex::Position0 | EVertex::TexCoord0);

	ds->vPosition0()[0] = glm::vec3(-1.0f, -1.0f, 0.0f);
	ds->vPosition0()[1] = glm::vec3(1.0f, -1.0f, 0.0f);
	ds->vPosition0()[2] = glm::vec3(1.0f, 1.0f, 0.0f);

	ds->vTexcoord0()[0] = glm::vec2(0.0f, 0.0f);
	ds->vTexcoord0()[1] = glm::vec2(1.0f, 0.0f);
	ds->vTexcoord0()[2] = glm::vec2(1.0f, 1.0f);

	ds->vPosition0()[3] = glm::vec3(-1.0f, -1.0f, 0.0f);
	ds->vPosition0()[4] = glm::vec3(1.0f, 1.0f, 0.0f);
	ds->vPosition0()[5] = glm::vec3(-1.0f, 1.0f, 0.0f);

	ds->vTexcoord0()[3] = glm::vec2(0.0f, 0.0f);
	ds->vTexcoord0()[4] = glm::vec2(1.0f, 1.0f);
	ds->vTexcoord0()[5] = glm::vec2(0.0f, 1.0f);

	g_Renderer->GetDynGeometryMgr()->EndGeometryAndDraw(ETopology::Triangles, 0, 6);

	return true;
}

/*--------------------------------------------------------------------------*/
